﻿using System;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;

namespace ServerControls.ImageLink
{
    public class ImageLink : WebControl
    {
        public string ImageUrl
        {
            get { return (string)ViewState["ImageUrl"]; }
            set { ViewState["ImageUrl"] = value; }
        }

        public string NavigationUrl
        {
            get { return (string)ViewState["NavigationUrl"]; }
            set { ViewState["NavigationUrl"] = value; }
        }

        public string OnClientClick
        {
            get { return (string)ViewState["OnClientClick"]; }
            set { ViewState["OnClientClick"] = value; }
        }

        protected override void RenderContents(HtmlTextWriter output)
        {
            StringBuilder sb = new StringBuilder();

            if (OnClientClick != null)
            {
                sb.Append("<a href=\"#\" onclick=\"" + OnClientClick  + "\">");
            }
            else
            {
                sb.Append("<a href=\"" + NavigationUrl + "\">");
            }

            sb.Append("<img src=\"" + ImageUrl + "\" border=\"0\">");
            sb.Append("</a>");

            output.Write(sb.ToString());
        }
    }
}
